﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;

namespace WeeGODAL
{
    public class DLMovie
    {
        public IQueryable<dynamic> FindData(int p_Dno)
        {
            MovieEntities context = new MovieEntities();
            var dp = from d in context.tbMovie
                     where d.MovID == p_Dno
                     select new
                     {
                         d.MovID,
                         d.MovName,
                         d.MovLanguage
                     };
            return dp;
        }


        /// <summary>
        /// 张晨-Finished
        /// 被Movie类的GetMovImage(string p_MovID)函数调用
        /// 剧照
        /// </summary>
        /// <returns>图片url(Json)</returns>
        public IQueryable<dynamic> GetMovImage(int p_MovID)
        {
            MovieEntities context = new MovieEntities();
            var data = from p in context.tbMovPhoto
                       where p.MovID == p_MovID
                       select new
                       {
                           p.MovID,
                           p.MovPhoto,
                           p.MovPhotoID
                       };
            return data;
        }

        /// <summary>
        /// 作者：张晨
        /// 状态：Finished
        /// 返回影片信息
        /// 被Movie类里的GetMovInfo(string p_MovID)调用
        /// </summary>
        /// <param name="p_MovID"></param>
        /// <returns></returns>
        public IQueryable<dynamic> GetMovInfo(int p_MovID)
        {
            MovieEntities context = new MovieEntities();
            var data = from p in context.tbMovie
                       where p.MovID == p_MovID
                       select new
                       {
                           p.MovActor,
                           p.MovCountry,
                           p.MovDirector,
                           p.MovID,
                           p.MovImage,
                           p.MovLanguage,
                           p.MovName,
                           p.MovPlayDate,
                           p.MovScore,
                           p.MovTime,
                           p.MovTrailer,
                           p.MovType
                       };
            return data;
        }

        /// <summary>
        /// 作者：张晨
        /// 状态：Finished
        /// 返回电影描述
        /// 被Movie类里的GetMovDesc(string p_MovID)调用
        /// </summary>
        /// <param name="p_MovID"></param>
        /// <returns></returns>
        public IQueryable<dynamic> GetMovDesc(int p_MovID)
        {
            MovieEntities context = new MovieEntities();
            var data = from p in context.tbMovie
                       where p.MovID == p_MovID
                       select new
                       {
                           p.MovDescription
                       };
            return data;

        }

        /// <summary>
        /// 作者：张晨
        /// 状态：Finished
        /// 被Movie类里的GetMovTrailer(string p_MovID)调用
        /// 返回影片的预告片地址
        /// </summary>
        /// <param name="p_MovID"></param>
        /// <returns></returns>
        public IQueryable<dynamic> GetMovTrailer(int p_MovID)
        {
            MovieEntities context = new MovieEntities();
            var data = from p in context.tbMovie
                       where p.MovID == p_MovID
                       select new
                       {
                           p.MovTrailer
                       };
            return data;
        }

        /// <summary>
        /// 作者：张晨
        /// 状态：Finished
        /// 获取MovID
        /// 被Movie类里的GetMovID(string p_MovName)函数调用
        /// </summary>
        /// <param name="p_MovName"></param>
        /// <returns></returns>
        public IQueryable<dynamic> GetMovID(string p_MovName)
        {
            MovieEntities context = new MovieEntities();
            var data = from p in context.tbMovie
                       where p.MovName == p_MovName
                       select new
                       {
                           p.MovID
                       };
            return data;
        }

        /// <summary>
        /// 作者：张晨
        /// 状态：Finished
        /// 作用：得到显示的MovName
        /// 被Movie类里的GetMovName()调用
        /// </summary>
        /// <returns></returns>
        public IQueryable<dynamic> GetMovName()
        {
            MovieEntities context = new MovieEntities();
            var data = from p in context.tbMovie
                       orderby p.MovPlayDate descending
                       select new
                       {
                           p.MovName
                       };
            return data.Take(10);
        }

        //影片搜索
        //根据movieName搜索电影信息
        //返回json型的电影信息
        /// <summary>
        /// 作者：张晨
        /// 状态：Finished
        /// 被Movie类里的SearchMov(string p_SearchName, string p_SearchType)函数调用
        /// </summary>
        /// <param name="p_SearchName"></param>
        /// <param name="p_SearchType"></param>
        /// <returns></returns>
        public IQueryable<dynamic> SearchMovByName(string p_SearchName)
        {
            MovieEntities context = new MovieEntities();
            var data = from p in context.tbMovie
                       where p.MovName.Contains(p_SearchName)
                       select new
                       {
                           p.MovActor,
                           p.MovCountry,
                           p.MovDirector,
                           p.MovID,
                           p.MovImage,
                           p.MovLanguage,
                           p.MovName,
                           p.MovPlayDate,
                           p.MovScore,
                           p.MovTime,
                           p.MovTrailer,
                           p.MovType
                       };
            return data;
        }


        //影片搜索
        //根据actor搜索电影信息
        //返回json型的电影信息
        /// <summary>
        /// 作者：张晨
        /// 状态：Finished
        /// 被Movie类里的SearchMov(string p_SearchName, string p_SearchType)函数调用
        /// </summary>
        /// <param name="p_SearchName"></param>
        /// <param name="p_SearchType"></param>
        /// <returns></returns>
        public IQueryable<dynamic> SearchMovByActor(string p_SearchName)
        {
            MovieEntities context = new MovieEntities();
            var data = from p in context.tbMovie
                       where p.MovActor.Contains(p_SearchName)
                       select new
                       {
                           p.MovActor,
                           p.MovCountry,
                           p.MovDirector,
                           p.MovID,
                           p.MovImage,
                           p.MovLanguage,
                           p.MovName,
                           p.MovPlayDate,
                           p.MovScore,
                           p.MovTime,
                           p.MovTrailer,
                           p.MovType
                       };
            return data;
        }


        //影片搜索
        //根据director搜索电影信息
        //返回json型的电影信息
        /// <summary>
        /// 作者：张晨
        /// 状态：Finished
        /// 被Movie类里的SearchMov(string p_SearchName, string p_SearchType)函数调用
        /// </summary>
        /// <param name="p_SearchName"></param>
        /// <param name="p_SearchType"></param>
        /// <returns></returns>
        public IQueryable<dynamic> SearchMovByDirector(string p_SearchName)
        {
            MovieEntities context = new MovieEntities();
            var data = from p in context.tbMovie
                       where p.MovDirector.Contains(p_SearchName)
                       select new
                       {
                           p.MovActor,
                           p.MovCountry,
                           p.MovDirector,
                           p.MovID,
                           p.MovImage,
                           p.MovLanguage,
                           p.MovName,
                           p.MovPlayDate,
                           p.MovScore,
                           p.MovTime,
                           p.MovTrailer,
                           p.MovType
                       };
            return data;
        }


        //影片搜索
        //根据all搜索电影信息
        //返回json型的电影信息
        /// <summary>
        /// 作者：张晨
        /// 状态：Finished
        /// 被Movie类里的SearchMov(string p_SearchName, string p_SearchType)函数调用
        /// </summary>
        /// <param name="p_SearchName"></param>
        /// <param name="p_SearchType"></param>
        /// <returns></returns>
        public IQueryable<dynamic> SearchMovByALL(string p_SearchName)
        {
            MovieEntities context = new MovieEntities();
            var data = from p in context.tbMovie
                       where p.MovDirector.Contains(p_SearchName) || p.MovActor.Contains(p_SearchName) || p.MovName.Contains(p_SearchName)
                       select new
                       {
                           p.MovActor,
                           p.MovCountry,
                           p.MovDirector,
                           p.MovID,
                           p.MovImage,
                           p.MovLanguage,
                           p.MovName,
                           p.MovPlayDate,
                           p.MovScore,
                           p.MovTime,
                           p.MovTrailer,
                           p.MovType
                       };
            return data;
        }

    }
}
